<%@ page language = "java" import = "java.util.*,edu.colorado.karl.devices.*" %>

<html>
<head>
  <TITLE>IntelliCORE - Current State</TITLE>
  <link rel="stylesheet" type="text/css" media="screen" charset="utf-8" href="css/common.css" />
</head>
<body>
<%@ include file="header.jspf" %>

<p><h1>Current State</h1></p>

<p>This page displays information about the current conditions in the house.</p>

<% 
	int dev;
	try {
		dev = Integer.parseInt(request.getParameter("dev"));
	} catch (Exception e) {
		dev = 0;
	}
	
	if(dev == 0) {	// Room State
		RoomState rs = new RoomState();
		double[] airTemps = rs.getAirTemps();
%>

		<p>
		Room Temperature: <b><%=airTemps[0]%>&#176;F</b>
		</p>
		
		<p>
		Outside Temperature: <%=airTemps[1]%>&#176;F
		</p>

<%	
		int[] setpoints = rs.getSetPoints(airTemps[0]);
%>

		<p>
		House will start heating when temperature falls below 
		<%=setpoints[0] - setpoints[1]%>&#176;F.<br />
		House will start cooling when temperature falls below 
		<%=setpoints[0] + setpoints[1]%>&#176;F.
		</p>

		<p>
<%
		//	Determine house heating mode
		String mode;
		if(setpoints[2] == 1)
			mode = "heating";
		else if(setpoints[2] == -1)
			mode = "cooling";
		else
			mode = "off";
%>
		House is currently <%=mode%>.
		</p>

<%
	} else if(dev == 1) {	// Water tanks
		WaterTanks wt = new WaterTanks();
		double[] tankTemps = wt.getTankTemperatures();
%>
		<p>
		Hot Tank Temperature: <%=tankTemps[0]%>&#176;F<br />
		Cold Tank Temperature: <%=tankTemps[1]%>&#176;F
		</p>
		
<%		
	} else if(dev == 2) {	// Solar Panels
		SolarPanels sp = new SolarPanels();
		double[] flowTemps = sp.getFlowTemperatures(); 
%>
		<p>
		The solar panels are currently <%=sp.getCurrentTemperature()%>&#176;F
		</p>
		
		<p>
		Solar Panel Supply Temperature: <%=flowTemps[1]%>&#176;F<br />
		Solar Panel Return Temperature: <%=flowTemps[0]%>&#176;F		
		</p>
<%
	} else if(dev == 3) {	// Heat Pump
		HeatPump hp = new HeatPump();
		double[] pumpTemps = hp.getPipeTemperatures();
%>
		<p>Heat Pump pipe input and output temperatures:</p>
		
		<p>
		Cold Input: <%=pumpTemps[0]%>&#176;F<br />
		Cold Output: <%=pumpTemps[1]%>&#176;F<br />
		Hot Input: <%=pumpTemps[2]%>&#176;F<br />
		Hot Output: <%=pumpTemps[3]%>&#176;F
		</p>
<%		
	} else if(dev == 4) {	// Hot Water
		HotWater hw = new HotWater();
		double[] waterTemps = hw.getWaterTemperatures();
%>
		<p>Domestic Hot Water is currently <%=waterTemps[0]%>&#176;F.</p>
		
		<p>
		Heat Pump Input Temperature: <%=waterTemps[1]%>&#176;F<br />
		Heat Pump Output Temperature: <%=waterTemps[2]%>&#176;F
		</p>
<%		
	}
%>

<p>
<%
	// Print out pictures
	if(dev == 0) {
%>
		<IMG src="/img/rs-on.png">
		<a href="currentstate.jsp?dev=1"><IMG src="/img/wt-off.png"></a>
		<a href="currentstate.jsp?dev=2"><IMG src="/img/sp-off.png"></a>
		<a href="currentstate.jsp?dev=3"><IMG src="/img/hp-off.png"></a>
		<a href="currentstate.jsp?dev=4"><IMG src="/img/hw-off.png"></a>
<%
	} else if (dev == 1) {
%>
		<a href="currentstate.jsp?dev=0"><IMG src="/img/rs-off.png"></a>
		<IMG src="/img/wt-on.png">
		<a href="currentstate.jsp?dev=2"><IMG src="/img/sp-off.png"></a>
		<a href="currentstate.jsp?dev=3"><IMG src="/img/hp-off.png"></a>
		<a href="currentstate.jsp?dev=4"><IMG src="/img/hw-off.png"></a>	
<%
	} else if (dev == 2) {
%>
		<a href="currentstate.jsp?dev=0"><IMG src="/img/rs-off.png"></a>
		<a href="currentstate.jsp?dev=1"><IMG src="/img/wt-off.png"></a>
		<IMG src="/img/sp-on.png">
		<a href="currentstate.jsp?dev=3"><IMG src="/img/hp-off.png"></a>
		<a href="currentstate.jsp?dev=4"><IMG src="/img/hw-off.png"></a>	
<%
	} else if (dev == 3) {
%>
		<a href="currentstate.jsp?dev=0"><IMG src="/img/rs-off.png"></a>
		<a href="currentstate.jsp?dev=1"><IMG src="/img/wt-off.png"></a>
		<a href="currentstate.jsp?dev=2"><IMG src="/img/sp-off.png"></a>
		<IMG src="/img/hp-on.png">
		<a href="currentstate.jsp?dev=4"><IMG src="/img/hw-off.png"></a>
<%
	} else if (dev == 4) {
%>
		<a href="currentstate.jsp?dev=0"><IMG src="/img/rs-off.png"></a>
		<a href="currentstate.jsp?dev=1"><IMG src="/img/wt-off.png"></a>
		<a href="currentstate.jsp?dev=2"><IMG src="/img/sp-off.png"></a>
		<a href="currentstate.jsp?dev=3"><IMG src="/img/hp-off.png"></a>
		<IMG src="/img/hw-on.png">
<%
	}
%>
</p>


<%@ include file="footer.jspf" %>
